#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int maxProfit(vector<int>&& prices) {
    int n = prices.size();
    vector<vector<int>> dp(n + 10, vector<int>(3, 0));

    dp[1][0] = -prices[0];
    for (int i = 2; i <= n; ++i)
    {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] - prices[i - 1]);
        dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][2] = dp[i - 1][0] + prices[i - 1];
    }

    return max(dp[n][1], dp[n][2]);
}

int main()
{
    maxProfit({1, 2,4});
	return 0;
}